package com.ojoin.ojoin.eb_spider.check;

import com.ojoin.ojoin.eb_spider.bean.CiMingUserOrder;
import com.ojoin.ojoin.eb_spider.bean.TJUserOrder;
import com.ojoin.ojoin.eb_spider.dao.CatchDataResultMapper;
import com.ojoin.ojoin.eb_spider.dao.MeinianUserMapper;
import com.ojoin.ojoin.eb_spider.domain.AlipayCheckException;
import com.ojoin.ojoin.eb_spider.domain.AssistCatchData;
import com.ojoin.ojoin.eb_spider.domain.EmailMessage;
import com.ojoin.ojoin.eb_spider.listening.MeidiMeiMeiJiaYuanCatchDateListening;
import com.ojoin.ojoin.eb_spider.model.CatchDataResult;
import com.ojoin.ojoin.eb_spider.model.MeinianUser;
import com.ojoin.ojoin.eb_spider.service.*;
import com.ojoin.ojoin.eb_spider.service.catchdata.MeidiMeiMeiJiaYuanDataCatchServiceImpl;
import com.ojoin.ojoin.eb_spider.utils.Config;
import com.ojoin.ojoin.eb_spider.utils.SpringUtilsSpider;
import com.ojoin.ojoin.eb_spider.utils.WebServiceUtils;
import com.ojoin.trade.common.utils.LogUtils;
import com.ojoin.trade.common.utils.TimeUtils;
import com.ojoin.trade.supplyloan_core.web.domain.CatchDataStartMessage;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlPlatformInfo;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlPlatformUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
public class CiMingDispatcher {
    private Logger log = LoggerFactory.getLogger(CiMingDispatcher.class);



    @Scheduled(fixedRate = 1000 * 60)
    public void CiMingAppointment() {

        WebDriveBaseService service = SpringUtilsSpider
                .getBeanByClassName("CiMingAppointmentServiceImpl");

        String username = "zxyb2016";
        String password = "111111";

        try {
            //LogUtils.info(log,Thread.currentThread().getId()+"_"+Thread.currentThread().getName());
            boolean flag = service.login(username, password);

            service.deal();

        } catch (Exception e) {
            service.closeCatchData();
            LogUtils.error(log,e);
        }
    }

    @Scheduled(fixedRate = 1000 * 30)
    public void deal() {

        WebDriveBaseService service = SpringUtilsSpider
                .getBeanByClassName("CiMingAppointmentServiceImpl");
        try {
            CiMingUserOrder co = getCiMingUserOrder();
            service.repairDeal(co);

        } catch (Exception e) {
            log.error("",e);
        }
    }

    public CiMingUserOrder getCiMingUserOrder(){
        Random rd = new Random(1000);
        TJUserOrder to = new TJUserOrder();
        to.setId(rd.nextLong());
        to.setName("张文超");
        to.setIdcard("14233019891111621X");
        to.setIdcardtype((byte) 1);
        to.setIsMarried(true);
        to.setMobile("18649041578");
        to.setOrdertime(TimeUtils.getDate("2017-03-25"));
        to.setFrontName("北京大北窑分院");
        //map.put(Config.CM_PERSONGROUP,"1608109827");

        CiMingUserOrder co = new CiMingUserOrder(to);
        return co;
    }
}
